<template>
	<view class="mainpadding" v-if="pageShow">
		<view class="mainpadding ffffff radius flexcolumn">
			<view class="xiaohei fonweight sanshier">券码</view>
			<uqrcode ref="uqrcode" canvas-id="qrcode" @click="ewmfn" v-bind:value="qrcodeurl"
				:options="{ margin: 10}" size="150">
			</uqrcode>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: 1, //1课程，2场地，3赛事，4活动
				qrcodeurl:"",
				listid:"",
				pageShow:false,
				child_id:"",//场地子id
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.type = options.type
			if(this.type==2){
				this.child_id = options.child_id
			}
			this.getsystem()
		},
		methods: {
			ewmfn() {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {
						console.log(res);
						var i = [res.tempFilePath]; //获取当前页面的轮播图数据
						//uniapp预览轮播图
						uni.previewImage({
							current: 0, //预览图片的下标
							urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
						})
					}
				});
			},
			getsystem() {
				httpRequest.request('/api/index/getConfigInfo', 'POST', {}, false, false, true).then(res => {
					if(this.type==1){
						this.qrcodeurl = res.data.kcdzp_url + "?hxid=" + this.listid
					}
					if(this.type==2){
						this.qrcodeurl = res.data.cddzp_url + "?hxid=" + this.listid+"&child_id="+this.child_id
					}
					if(this.type==3){
						this.qrcodeurl = res.data.ssdzp_url + "?hxid=" + this.listid
					}
					if(this.type==4){
						this.qrcodeurl = res.data.activitydzp_url + "?hxid=" + this.listid
					}
					this.pageShow = true
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.erweima {
		margin: 60rpx auto 0;
		height: 240rpx;
		width: 240rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	page {
		background: #F9F9F9;
	}
</style>